package dhm.com.dhmshop.view.home;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dhm.com.dhmshop.R;
import dhm.com.dhmshop.adapter.home.GoodsPingAdapter;
import dhm.com.dhmshop.base.BaseActiity;
import dhm.com.dhmshop.base.Presenter.PressenterImpl;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.base.netWork.LoginContract;
import dhm.com.dhmshop.entity.PingListBean;
import dhm.com.dhmshop.framework.module.commodity.entity.OneGoodsEntity;
import dhm.com.dhmshop.utils.SpUtils;

public class GoodspingActivity extends BaseActiity implements LoginContract.IView {

    @BindView(R.id.one)
    TextView one;
    @BindView(R.id.two)
    TextView two;
    @BindView(R.id.three)
    TextView three;
    @BindView(R.id.recy)
    RecyclerView recy;
    private int gid;
    private String uid;
    private PressenterImpl pressenter;
    private GoodsPingAdapter goodsPingAdapter;

    int page=1;



    @Override
    protected int getLayout() {
        return R.layout.activity_goodsping;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        gid = getIntent().getIntExtra("gid",1);
        uid = SpUtils.getString(this, "uid");
        pressenter = new PressenterImpl();
        pressenter.attachView(this);

        LinearLayoutManager manager=new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recy.setLayoutManager(manager);
        goodsPingAdapter = new GoodsPingAdapter(this);
        recy.setAdapter(goodsPingAdapter);
        page=1;

    }

    @Override
    protected void initData() {
        Map<String, String> map = new HashMap<>();
        map.put("token", Constant.TOKEN);
        map.put("goodsId", gid+"");
        map.put("page",page+"");
        pressenter.sendMessage(this, Constant.GetGoodsAppriseList, map, PingListBean.class);
    }

    @Override
    public void requesta(Object data) {
        if (data instanceof PingListBean){
            PingListBean oneGoodsEntity= (PingListBean) data;
            if (oneGoodsEntity.getCode()==1){
                goodsPingAdapter.setShopList(oneGoodsEntity.getData());
            }else {
                Toast.makeText(this, "暂无商品评价", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    public void fail(String error) {

    }

    @OnClick({R.id.back, R.id.one, R.id.two, R.id.three})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.one:
                one.setBackgroundResource(R.drawable.back_main);
                two.setBackgroundResource(R.drawable.type_ordern);
                three.setBackgroundResource(R.drawable.type_ordern);
                one.setTextColor(getResources().getColor(R.color.white));
                two.setTextColor(getResources().getColor(R.color.mainblack));
                three.setTextColor(getResources().getColor(R.color.mainblack));
                break;
            case R.id.two:
                two.setBackgroundResource(R.drawable.back_main);
                one.setBackgroundResource(R.drawable.type_ordern);
                three.setBackgroundResource(R.drawable.type_ordern);
                two.setTextColor(getResources().getColor(R.color.white));
                one.setTextColor(getResources().getColor(R.color.mainblack));
                three.setTextColor(getResources().getColor(R.color.mainblack));
                break;
            case R.id.three:
                three.setBackgroundResource(R.drawable.back_main);
                two.setBackgroundResource(R.drawable.type_ordern);
                one.setBackgroundResource(R.drawable.type_ordern);
                three.setTextColor(getResources().getColor(R.color.white));
                two.setTextColor(getResources().getColor(R.color.mainblack));
                one.setTextColor(getResources().getColor(R.color.mainblack));
                break;
            default:
        }
    }
}
